package com.cskaoyan.controller.wx.goods;

import com.cskaoyan.bean.common.BaseParam;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.po.MarketGoods;
import com.cskaoyan.bean.vo.wx.SearchGoodsAndCategoryListVo;
import com.cskaoyan.bean.vo.wxgoodsvo.RelatedGoodsVo;
import com.cskaoyan.bean.vo.wxgoodsvo.WxGoodsCategoryBo;
import com.cskaoyan.bean.vo.wxgoodsvo.WxGoodsDetailVo;
import com.cskaoyan.service.wx.WxSearchService;
import com.cskaoyan.service.wx.goodsService.WxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:todo 处理商品 GET
 * @Author:todo wang xv
 * @Date:todo 2022/11/22
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {

    @Autowired
    WxGoodsService wxGoodService;

    @Autowired
    WxSearchService wxSearchServiceImpl;

    /**
     * @Description:todo 显示商品数量 GET
     * @Author:todo wang xv
     * @Date:todo 2022/11/22
     */
    @RequestMapping("count")
    public BaseRespVo queryGoodsNum() {
        Integer goodsNum = wxGoodService.getGoodsNum();
        return BaseRespVo.succeed(goodsNum);
    }

    /**
     * @Description:todo 根据父目类id查询相关目类 GET
     * @Author:todo wang xv
     * @Date:todo 2022/11/22
     */
    @RequestMapping("category")
    public BaseRespVo queryCategory(Integer id) {
        WxGoodsCategoryBo categoryBo = wxGoodService.queryCategory(id);
        return BaseRespVo.succeed(categoryBo);
    }

    /**
     * 根据对应的搜索关键字寻找对应的商品
     *
     * @param baseParam  商品分页规则
     * @return 对应的数据
     */
    @RequestMapping("list")
    public BaseRespVo selectGoodsByKeyword(BaseParam baseParam, MarketGoods marketGoods,String keyword) {

        // 首先要将当前的关键词存入该用户的历史关键词中
        if (keyword != null){
            wxSearchServiceImpl.insertHistoryKeyword(keyword);
        }
        // 查询商品和类目信息
        SearchGoodsAndCategoryListVo goods = wxGoodService.selectGoodsByKeyword(baseParam,marketGoods,keyword);

        return BaseRespVo.succeed(goods);
    }

    /**
     * @Description:todo 根据商品的id查询商品的细节
     * @Author:todo wang xv
     * @Date:todo 2022/11/23
     */
    @RequestMapping("detail")
    public BaseRespVo queryGoodsDetail(Integer id) {
        WxGoodsDetailVo detailVo = wxGoodService.queryGoodsDetail(id);
        return BaseRespVo.succeed(detailVo);
    }

    /**
    * @Description:todo 显示相关联的商品
    * @Author:todo wang xv
    * @Date:todo 2022/11/23
    */
    @RequestMapping("related")
    private BaseRespVo queryRelatedGoods(Integer id){
        RelatedGoodsVo goodsVo = wxGoodService.getRelatedGoods(id);
        return BaseRespVo.succeed(goodsVo);
    }

}
